using System.Collections.Generic;
using System.Xml.Linq;

namespace TDUnit.TestDataParsers.XmlParser
{
    public class DocumentProcessorPipeline
    {
        private readonly List<IXmlTestDataProcessor> processors = new List<IXmlTestDataProcessor>();

        public void Process(XDocument document)
        {
            foreach (var p in processors)
            {
                p.Process(document);
            }
        }

        public void AddProcessor(IXmlTestDataProcessor processor)
        {
            processors.Add(processor);
        }

        public void RemoveProcessor(IXmlTestDataProcessor processor)
        {
            processors.Remove(processor);
        }

        public void Clear()
        {
            processors.Clear();
        }

        public DocumentProcessorPipeline WithProcessor(IXmlTestDataProcessor processor)
        {
            processors.Add(processor);
            return this;
        }
    }
}